//
//  FBOrderTableViewCell.m
//  XTXOneToOne
//
//  Created by Canny on 2018/11/1.
//  Copyright © 2018年 WK. All rights reserved.
//

#import "FBOrderTableViewCell.h"


@interface FBOrderTableViewCell ()

@property (nonatomic,strong)UILabel * logo;

@property (nonatomic,strong)UILabel * name;

@property (nonatomic,strong)UILabel * lab1;

@property (nonatomic,strong)UILabel * lab2;

@property (nonatomic,strong)UILabel * lab3;


@property (nonatomic,strong)UILabel * lab4;


@end

@implementation FBOrderTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self){
        [self initView];
    }
    return self;
}

-(void)setLab:(UILabel *)lab withColor:(UIColor *)color andFont:(CGFloat)font andText:(NSString *)text andTextAlignment:(NSTextAlignment)textAlignment{
    lab.text=text;
    lab.textColor=color;
    lab.font=[UIFont systemFontOfSize:font];
    lab.textAlignment=textAlignment;
}


- (void)initView{
    
    self.backgroundColor=[UIColor whiteColor];
    
    UILabel * logo = [[UILabel alloc]init];
    [self addSubview:logo];
    logo.frame=CGRectMake(15, 10, 25, 25);
    [self setLab:logo withColor:[UIColor whiteColor] andFont:15 andText:@"" andTextAlignment:NSTextAlignmentCenter];
    logo.layer.cornerRadius=12.5;
    logo.clipsToBounds=YES;
    logo.backgroundColor=ThemeColor;
    _logo=logo;
    
    UILabel * name = [[UILabel alloc]init];
    [self addSubview:name];
    [self setLab:name withColor:RGB(30, 63, 89) andFont:15 andText:@"" andTextAlignment:NSTextAlignmentLeft];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(logo.mas_centerY).offset(0);
        make.left.equalTo(logo.mas_right).offset(15);
        make.right.equalTo(self.mas_right).offset(-10);
        make.height.mas_equalTo(20);
    }];
    _name=name;
    
    UILabel * lab3 = [[UILabel alloc]init];
    [self addSubview:lab3];
    [self setLab:lab3 withColor:RGB(131, 151, 167) andFont:12 andText:@"加载中..." andTextAlignment:NSTextAlignmentRight];
    [lab3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-15);
        make.left.equalTo(self.mas_left).offset(15);
        make.centerY.equalTo(name.mas_centerY).offset(0);
        make.height.mas_equalTo(20);
    }];
    _lab3=lab3;
    
    UIView * line1 =[[UIView alloc]init];
    [self addSubview:line1];
    line1.backgroundColor=RGB(231, 235, 238);
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(logo.mas_bottom).offset(10);
        make.height.mas_equalTo(1);
    }];
    
    UILabel * lab1 = [[UILabel alloc]init];
    [self addSubview:lab1];
    [self setLab:lab1 withColor:RGB(30, 63, 89) andFont:15 andText:@"加载中..." andTextAlignment:NSTextAlignmentLeft];
    [lab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(line1.mas_bottom).offset(10);
        make.height.mas_equalTo(20);
        
    }];
    lab1.font=[UIFont boldSystemFontOfSize:15];
    _lab1=lab1;
    
    
    UILabel * lab4 = [[UILabel alloc]init];
    [self addSubview:lab4];
    [self setLab:lab4 withColor:RGB(131, 151, 167) andFont:15 andText:@"加载中..." andTextAlignment:NSTextAlignmentRight];
    [lab4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-15);
        make.left.equalTo(self.mas_left).offset(15);
        make.centerY.equalTo(lab1.mas_centerY).offset(0);
        make.height.mas_equalTo(20);
        
    }];
    _lab4=lab4;
    
    UILabel * lab2 = [[UILabel alloc]init];
    [self addSubview:lab2];
    [self setLab:lab2 withColor:RGB(30, 63, 89) andFont:15 andText:@"加载中..." andTextAlignment:NSTextAlignmentLeft];
    [lab2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(15);
        make.top.equalTo(lab1.mas_bottom).offset(10);
        make.height.mas_equalTo(20);
        
    }];
    lab2.font=[UIFont boldSystemFontOfSize:15];
    _lab2=lab2;
    
    UIImageView * imgVArrow = [[UIImageView alloc]init];
    [self addSubview:imgVArrow];
    [imgVArrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-15);
        make.centerY.equalTo(lab2.mas_centerY);
        make.width.equalTo(@(6));
        make.height.equalTo(@(12));
    }];
    imgVArrow.image=[UIImage imageNamed:@"进入icon"];
    
    UIView * line2 =[[UIView alloc]init];
    [self addSubview:line2];
    line2.backgroundColor=RGB(231, 235, 238);
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(0);
        make.left.equalTo(self.mas_left).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(0);
        make.height.mas_equalTo(10);
    }];
    
   
    
    
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}



-(void)setDataSource:(FBAllOrderModel *)dataSource{
    _dataSource = dataSource;
    
    if (_dataSource) {
        
        NSString * nickname=[NSString stringWithFormat:@"%@",dataSource.nickname];
        if (nickname.length>0) {
            _logo.text = [nickname substringToIndex:1];
        }
        _name.text=nickname;
        
        _lab2.text =[NSString stringWithFormat:@"%@ %@",dataSource.price,dataSource.legal];
        
        _lab3.text= [NSString stringWithFormat:@"%@",dataSource.create_time];
        
        //订单状态，@0：待付款；@1：已付款（未释放代币）；@2：已释放代币；@3：申诉中；@4：已取消
        NSString *status=[NSString stringWithFormat:@"%@",dataSource.status];
        if ([status integerValue]==0) {
            _lab4.text = @"待付款";
        }else if ([status integerValue]==1){
            _lab4.text = @"已付款";
        }else if ([status integerValue]==2){
            _lab4.text = @"订单成功";
        }else if ([status integerValue]==3){
            _lab4.text = @"申诉中";
        }else if ([status integerValue]==4){
            _lab4.text = @"已取消";
        }
        if ([status integerValue]==0||[status integerValue]==1) {
         _lab4.textColor=[UIColor redColor];
         _lab4.font = [UIFont boldSystemFontOfSize:15];
        }else{
            _lab4.textColor = RGB(131, 151, 167);
            _lab4.font = [UIFont systemFontOfSize:15];
        }
        
        // @1:买；@2：卖

        if ([dataSource.order_type integerValue]==1) {
            
            NSString * str = [NSString stringWithFormat:@"购买%@",dataSource.symbol];
            NSRange range = [str rangeOfString:@"购买"];
            NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:str];
            
            [attri addAttribute:NSForegroundColorAttributeName value:RGB(4, 192, 135) range:NSMakeRange(range.location, range.length)];
            
            _lab1.attributedText=attri;

        }else if ([dataSource.order_type integerValue]==2){

            NSString * str = [NSString stringWithFormat:@"出售%@",dataSource.symbol];
            NSRange range = [str rangeOfString:@"出售"];
            NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:str];
            
            [attri addAttribute:NSForegroundColorAttributeName value:RGB(231, 109, 66) range:NSMakeRange(range.location, range.length)];
            
            _lab1.attributedText=attri;
        }
        
    }
    
    
}

+(CGFloat)computeHeight:(id)info{
    
    return 135;
    
}

@end





















